package com.mryx.demo.mapper;

import com.mryx.demo.pojo.Cart;
import com.mryx.demo.pojo.Details;
import com.mryx.demo.pojo.Order;
import com.mryx.demo.pojo.Picture;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 订单接口
 */
@Repository
public interface OrderMapper {

    /**
     * 生成订单
     * @return  400:失败 200:成功
     */
    @Insert("insert into `order` (uid,state,prices,ordernum) values (#{uid},#{state},#{prices},#{ordernum})")
     int InOrder(Order order);
    /**
     * 生成订单详情
     * @return  400:失败 200:成功
     */
    @Insert("insert into details (ordernum,cid,number,price,prices) values (#{ordernum},#{cid},#{number},#{price},#{prices})")

    int InDetas(Details details);

    /**
     * 查看订单中商品图片
     * @return   List<Picture>
     * @Pram    ordernum
     */
    @Select("SELECT commodity.cid,route from details LEFT JOIN commodity ON details.cid =commodity.cid LEFT JOIN picture ON commodity.cid=picture.cid WHERE details.ordernum=#{ordernum}")
    List<Picture> picture(String ordernum);

    /**
     * 查看个人订单
     * @return   List<Order>
     */
    @Select("select state,generate,prices,ordernum from `order` where uid=#{uid}")
    List<Order> showAll(int uid);


    /**
     * 查看个人订单(详细类别)
     * @return  List<Order>
     * @param   state
     */
    @Select("select state,generate,prices,ordernum from `order` where uid=#{uid} and state=#{state}")
    List<Order> showByClass(@Param("uid") int uid,@Param("state") int state);

    /**
     * 修改订单状态(代发货,发货,配送中)
     * @return  400:失败;200:成功
     * @param  order
     */
    @Update("update `order` set state=#{state} where ordernum=#{ordernum}")
    int Update(Order order);

    /**
     * 查看商品单价
     * @return    price
     */
    @Select("select price from commodity where cid=#{cid}")
    Double  ComPrice(int cid);

    /**
     * 查看商品图片
     * @return    price
     */
    @Select("select price from commodity where cid=#{cid}")
    String  Compicture(int cid);

    /**
     * 删除购物车
     * @return    uid,cid
     */
    @Delete("delete from  cart where uid=#{uid} and cid=#{cid}")
    String  DelCart(Cart cart);

}
